package com.liang.pattern.store.impl;

import com.alibaba.fastjson.JSON;
import com.liang.pattern.store.ICommodity;
import org.itstack.demo.design.goods.DeliverReq;
import org.itstack.demo.design.goods.GoodsService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * @author lsm
 * @ClassName GoodsCommodity.java
 * @Description TODO
 * @createTime 2023年11月29日 15:03:00
 */
public class GoodsCommodity implements ICommodity {

    Logger logger = LoggerFactory.getLogger(GoodsCommodity.class);

    private GoodsService goodsService = new GoodsService();

    @Override
    public void sendCommodity(String uId, String commodityId, String bizId, Map<String, String> extMap) {
        DeliverReq deliverReq = new DeliverReq();
        deliverReq.setUserName(queryNameByUid(uId));
        deliverReq.setUserPhone(queryNumberByUid(uId));
        deliverReq.setSku(commodityId);
        deliverReq.setOrderId(bizId);
        deliverReq.setConsigneeUserName(extMap.get("consigneeUserName"));
        deliverReq.setConsigneeUserPhone(extMap.get("consigneeUserPhone"));
        deliverReq.setConsigneeUserAddress(extMap.get("consigneeUserAddress"));

        Boolean aBoolean = goodsService.deliverGoods(deliverReq);
        logger.info("请求参数[优惠券] => uId：{} commodityId：{} bizId：{} extMap：{}", uId, commodityId, bizId, JSON.toJSON(extMap));
        logger.info("测试结果[优惠券]：{}", aBoolean);

        if(!aBoolean) {
            throw new RuntimeException("实物商品发放失败");
        }

    }

    private String queryNumberByUid(String uId){
        return "18377265578";
    }

    private String queryNameByUid(String uId){
        return "梁世民";
    }
}
